/**
 * 
 */
package hihocoder;

import java.util.Scanner;

/**
 * @author zhongfang
 *
 */
public class 小Hi的钟表 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int T=scanner.nextInt();
		for (int i = 0; i < T; i++) {
			int h=scanner.nextInt();
			int m=scanner.nextInt();
			int s=scanner.nextInt();
			int t=scanner.nextInt();
			//计算新的时间,不会超过int 范围
			s+=t;
			
			m+=s/60;
			s%=60;
			
			h+=m/60;
			m%=60;
			
			h%=12;
			
//			System.out.println("new time"+h+":"+m+":"+s);
			//计算时针与分针的夹角
			double shi=((double)(h*60*60+m*60+s))*360/(12*60*60);
			double fen=((double)(m*60+s)*360)/(60*60);
			double res=Math.abs(shi-fen);
			if(res>180){
				res=360-res;
			}
			System.out.println(String.format("%.4f", res));
		}
	}
}
